home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / dtype / fontdt12.lha / Src / classbase.c next >
C/C++ Source or Header  |  1996-05-06  |  4KB  |  134 lines

  1. /*
  2. **    classbase.c - implementation of standard function for Font DataType class
  3. **    Copyright © 1995-96 Michael Letowski
  4. */
  5.  
  6. #include <exec/types.h>
  7. #include <exec/execbase.h>
  8. #include <dos/dos.h>
  9. #include <support/types.h>
  10.  
  11. #include <proto/exec.h>
  12. #include <proto/intuition.h>
  13.  
  14. #include "classbase.h"
  15. #include "dispatch.h"
  16.  
  17.  
  18. /*
  19. **    Private constants
  20. */
  21. #define INT_NAME        "intuition.library"
  22. #define INT_VERN        39
  23. #define GFX_NAME        "graphics.library"
  24. #define GFX_VERN        39
  25. #define DOS_NAME        "dos.library"
  26. #define DOS_VERN        39
  27. #define UTIL_NAME        "utility.library"
  28. #define UTIL_VERN        39
  29. #define DT_NAME            "datatypes.library"
  30. #define DT_VERN            39
  31. #define DF_NAME            "diskfont.library"
  32. #define DF_VERN            39
  33. #define PDT_NAME        "datatypes/picture.datatype"
  34. #define PDT_VERN        39
  35.  
  36.  
  37. /*
  38. **    Public functions
  39. */
  40. ASM Class *ObtainFontEngine(R_A6 struct ClassBase *cb)
  41. {
  42.     return(cb->cb_Class);
  43. }    /* ObtainREKOEngine */
  44.  
  45. ASM struct ClassBase *LibInit(R_D0 struct ClassBase *cb, R_A0 BPTR segList,
  46.                                                             R_A6 struct Library *sysBase)
  47. {
  48.     cb->cb_SegList=segList;
  49.     cb->cb_SysBase=(struct ExecBase *)sysBase;
  50.  
  51.     InitSemaphore(&cb->cb_Lock);                                    /* Initialize locking */
  52.  
  53.     try(cb->cb_IntuitionBase=    OpenLibrary(INT_NAME,INT_VERN),        NO_INT);
  54.     try(cb->cb_GfxBase=                OpenLibrary(GFX_NAME,GFX_VERN),        NO_GFX);
  55.     try(cb->cb_DOSBase=                OpenLibrary(DOS_NAME,DOS_VERN),        NO_DOS);
  56.     try(cb->cb_UtilityBase=        OpenLibrary(UTIL_NAME,UTIL_VERN),    NO_UTIL);
  57.     return(cb);
  58.  
  59.     /* Exceptions */
  60.     catch(FOO,            );
  61.     catch(NO_UTIL,    CloseLibrary(cb->cb_UtilityBase));
  62.     catch(NO_DOS,        CloseLibrary(cb->cb_DOSBase));
  63.     catch(NO_GFX,        CloseLibrary(cb->cb_GfxBase));
  64.     catch(NO_INT,        CloseLibrary(cb->cb_IntuitionBase));
  65.     return(NULL);
  66. }    /* LibInit */
  67.  
  68. ASM struct ClassBase *LibOpen(R_A6 struct ClassBase *cb)
  69. {
  70.     ObtainSemaphore(&cb->cb_Lock);                                /* Protect library base */
  71.     fclr(cb->cb_Lib.lib_Flags,LIBF_DELEXP);                /* No delayed expunge */
  72.  
  73.     if(cb->cb_Lib.lib_OpenCnt==0 && cb->cb_Class==NULL)
  74.     {                                                                                            /* First open */
  75.         try(cb->cb_DataTypesBase=        OpenLibrary(DT_NAME,DT_VERN),        NO_DT);
  76.         try(cb->cb_DiskfontBase=        OpenLibrary(DF_NAME,DF_VERN),        NO_DF);
  77.         try(cb->cb_SuperClassBase=    OpenLibrary(PDT_NAME,PDT_VERN),    NO_PDT);
  78.         try(cb->cb_Class=InitClass(cb),                                                            NO_CLASS);
  79.     }
  80.  
  81.     cb->cb_Lib.lib_OpenCnt++;                                            /* Mark successfull opening */
  82.     ReleaseSemaphore(&cb->cb_Lock);                                /* Data modified */
  83.     return(cb);                                                                        /* Return success */
  84.  
  85.     catch(FOO,            );
  86.     catch(NO_CLASS,    FreeClass(cb->cb_Class));
  87.     catch(NO_PDT,        CloseLibrary(cb->cb_SuperClassBase));
  88.     catch(NO_DF,        CloseLibrary(cb->cb_DiskfontBase));
  89.     catch(NO_DT,        CloseLibrary(cb->cb_DataTypesBase));
  90.     ReleaseSemaphore(&cb->cb_Lock);                                /* Unlock base */
  91.     return(NULL);                                                                    /* Return failure */
  92. }    /* LibOpen */
  93.  
  94. ASM BPTR LibClose(R_A6 struct ClassBase *cb)
  95. {
  96.     BPTR Seg=0;
  97.  
  98.     ObtainSemaphore(&cb->cb_Lock);                                /* Protect library base */
  99.     if(cb->cb_Lib.lib_OpenCnt)
  100.         cb->cb_Lib.lib_OpenCnt--;                                        /* Decrease open count */
  101.     if(cb->cb_Lib.lib_OpenCnt==0 && cb->cb_Class)
  102.         if(FreeClass(cb->cb_Class))
  103.         {
  104.             cb->cb_Class=NULL;
  105.             CloseLibrary(cb->cb_SuperClassBase);
  106.             CloseLibrary(cb->cb_DiskfontBase);
  107.             CloseLibrary(cb->cb_DataTypesBase);
  108.         }
  109.         else
  110.             fset(cb->cb_Lib.lib_Flags,LIBF_DELEXP);
  111.     ReleaseSemaphore(&cb->cb_Lock);                                /* Unlock base */
  112.     if(ftst(cb->cb_Lib.lib_Flags,LIBF_DELEXP))        /* Delayed expunge set? */
  113.         Seg=LibExpunge(cb);
  114.     return(Seg);
  115. }    /* LibClose */
  116.  
  117. ASM BPTR LibExpunge(R_A6 struct ClassBase *cb)
  118. {
  119.     BPTR Seg=0;
  120.  
  121.     if(cb->cb_Class==NULL)                                                /* No accesors? */
  122.     {
  123.         Seg=cb->cb_SegList;
  124.         Remove((struct Node *)cb);                                    /* Remove from library list */
  125.         CloseLibrary(cb->cb_UtilityBase);
  126.         CloseLibrary(cb->cb_DOSBase);
  127.         CloseLibrary(cb->cb_GfxBase);
  128.         CloseLibrary(cb->cb_IntuitionBase);
  129.         FreeMem((APTR)((ULONG)(cb)-(ULONG)(cb->cb_Lib.lib_NegSize)),
  130.                         cb->cb_Lib.lib_NegSize + cb->cb_Lib.lib_PosSize);
  131.     }
  132.     return(Seg);
  133. }    /* LibExpunge */
  134.